package com.adobe.nativeExtensions
{
	import flash.events.EventDispatcher;
	import flash.events.StatusEvent;
	import flash.external.ExtensionContext;

	public class NotificationInterface extends EventDispatcher
	{
		private var context:ExtensionContext;
		
		public function NotificationInterface()
		{
			if( !context )
			{
				context = ExtensionContext.createExtensionContext("com.leebrimelow.notification", null);
				context.addEventListener( StatusEvent.STATUS, onStatusHandler );
			}
		}
		
		
		private function onStatusHandler( e:StatusEvent ):void 
		{		
			this.dispatchEvent( e.clone() );			
		}
	
		
		public function notify( message:String ): Object
		{
			return this.call("notify", message);
		}
		
		
		public function toast(pValue:String):Object 
		{				
			return this.call("toast", pValue);			
		}
		
		public function alertDialog(pTitle:String,pMessage:String):Object 
		{
			return call("alertDialog", pTitle, pMessage);			
		}
		
		public function timePickerDialog():Object 
		{
			return call("timePickerDialog");
		}
		
		public function devices():String 
		{
			return call("devices")+"";
		}
		
		public function itemListDialog(pTitle:String,pValue:String):Object 
		{
			return call("itemListDialog", pTitle, pValue );			
		}
		
		public function googleMap():Object 
		{
			return call("googleMap");
			
		}
		
		public function fileOpen( fileName:String ): Object
		{
			return call("fileOpenExtension", fileName);
		}
		
		public function fileDownLoad( fileName:String ): Object
		{
			return call("fileDownLoadExtension", fileName );
		}
		
		
		private function call(pName:String , ...args:Array):Object 
		{			
			if (this.context == null)
			{
				return null;
			}
			return this.context.call.apply( this , [pName].concat(args) ); 
		}
		
		
		
	}
}